<?php
/**
 * 
 * @author yantao
 *
 *
 */
class ApiController{

	const API_EACH_PAGE_MAXIMUM = 50;//每页显示最大条目数
	const API_EACH_PAGE_DEFAULT = 30;//每页显示默认条目数
	const API_BATCH_UTMOST = 50;//批量获取最大数量
	const API_SEARCH_EACH_PAGE_DEFAULTNUM = 20;//搜索默认结果数
	const API_COUNT_TYPE = 'amount';
	//用户ID
	public $user_id = null;

	public function __construct($user_id = null) {
		$this->user_id = $user_id;
	}

	public function throw_code($code) {
		throw new Exception($code);
	}

	public function get_current_user_id() {
		return $this->user_id;
	}

	/**
	 * 获取uid
	 *
	 * @param int $uid 参数为空则为当前用户
	 */
	public function get_user_id($uid) {
		$user_id = null;
		if( !empty($uid) ) {
			$user_id = $uid;
		} else {
			$user_id = $this->user_id;
		}
		if( intval($user_id) <= 0 ) {
			$this->throw_code(ApiErr::API_EC_PARAM);
		}
		return $user_id;
	}

	/**
	 * 接口列表长度统一处理
	 * 每页返回的最大条数，最大值50条，默认30条
	 *
	 * @param int $count
	 */
	public  function get_list_count($count) {
		if ($count > self::API_EACH_PAGE_MAXIMUM ) {
			$this->throw_code(ApiErr::API_EC_OVER_PAGELIMIT);
		} elseif ($count <= 0) {
			$count = self::API_EACH_PAGE_DEFAULT;
		}
		return $count;
	}

}	
